import 'package:animal/constant/index_constant.dart';
import 'package:animal/item/buttom_item.dart';
import 'package:animal/ui/friend/controller/friend_list_controller.dart';
import 'package:animal/ui/friend/model/friend_model.dart';
import 'package:animal/utils/screen_util.dart';
import 'package:animal/utils/utils.dart';
import 'package:animal/widgets/appbar_widget.dart';
import 'package:animal/widgets/azListView/my_az_listview.dart';
import 'package:azlistview/azlistview.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';

///通讯录-好友列表
class FriendListPage extends StatelessWidget {
  FriendListPage({Key? key}) : super(key: key);
  final controller = Get.put(FriendListController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: KColorConstant.appBgColor,
      resizeToAvoidBottomInset: false,
      appBar: PreferredSize(
        preferredSize: Size(double.infinity, ScreenUtil().L(45)),
        child: AppBarWidget.defaultAppBar(
            backgroundColor: Colors.white,
            automaticallyImplyLeading: false,
            centerTitle: false,
            elevation: 0.5,
            title: Text("通讯录",
                style: KFontConstant.myTextStyle(
                  size: 20,
                  bold: true,
                )),
            actions: [
              GFIconButton(
                icon: const Icon(
                  Icons.add,
                  color: Colors.blue,
                ),
                onPressed: () => controller.gotoAddFriend(),
                type: GFButtonType.transparent,
              ),
            ]),
      ),
      body: MyAzListView(
        data: controller.contactList,
        itemCount: controller.contactList.length,
        itemBuilder: (BuildContext context, int index) {
          FriendModel model = controller.contactList[index];
          return Utils.getWeChatListItem(
            context,
            model,
            defHeaderBgColor: const Color(0xFFE5E5E5),
          );
        },
        content: Container(
          width: double.infinity,
          color: Colors.white,
          child: Column(
            children: [
              InkWell(
                onTap: () => controller.gotoSearch(),
                child: Container(
                    margin: EdgeInsets.symmetric(horizontal: ScreenUtil().L(30), vertical: ScreenUtil().L(10)),
                    padding: EdgeInsets.symmetric(horizontal: ScreenUtil().L(20)),
                    height: ScreenUtil().L(35),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(color: const Color(0XFFF6F6F6), borderRadius: BorderRadius.circular(ScreenUtil().L(40))),
                    child: Row(
                      children: [
                        Image.asset("icons/icon_search.png", width: ScreenUtil().L(18)),
                        Text(
                          "搜索",
                          style: KFontConstant.myTextStyle(size: 16, color: const Color(0XFFBFC4CC)),
                        )
                      ],
                    )),
              ),
              Container(
                margin: EdgeInsets.symmetric(horizontal: ScreenUtil().L(40), vertical: ScreenUtil().L(20)),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    ButtonItem.iconTextButton(
                        child: GFIconBadge(
                          child: GFIconButton(
                            type: GFButtonType.transparent,
                            icon: Image.asset(
                              "images/friend_apply.png",
                            ),
                            onPressed: () => controller.gotoNewFriend(),
                            size: GFSize.LARGE,
                          ),
                          counterChild: controller.applyNum.value==0?Container():GFBadge(
                            text: controller.applyNum.value>=99?"99+":controller.applyNum.value.toString(),
                            textStyle: KFontConstant.myTextStyle(size: 10, color: Colors.white),
                            shape: GFBadgeShape.circle,
                            size: GFSize.MEDIUM,
                          ),
                        ),
                        text: "新的朋友"),
                    ButtonItem.iconTextButton(
                        child: GFIconButton(
                          type: GFButtonType.transparent,
                            onPressed: () =>controller.gotoGroup(),
                            icon: Image.asset(
                              "images/friend_group.png",
                            ),size: GFSize.LARGE,),
                        text: "群聊"),
                    ButtonItem.iconTextButton(
                        child: GFIconButton(
                          type: GFButtonType.transparent,
                            onPressed: () {},
                            icon: Image.asset(
                              "images/friend_custmer.png",
                            ),size: GFSize.LARGE,),
                        text: "火讯客服"),
                  ],
                ),
              ),
            ],
          ),
        ),
        physics: const BouncingScrollPhysics(),
        susItemBuilder: (BuildContext context, int index) {
          FriendModel model = controller.contactList[index];
          if ('↑' == model.getSuspensionTag()) {
            return Container();
          }
          return Utils.getSusItem(context, model.getSuspensionTag());
        },
        indexBarData: const ['↑', '☆', ...kIndexBarData],
        indexBarOptions: IndexBarOptions(
          needRebuild: true,
          ignoreDragCancel: true,
          downTextStyle: const TextStyle(fontSize: 12, color: Colors.white),
          downItemDecoration: const BoxDecoration(shape: BoxShape.circle, color: Colors.green),
          indexHintWidth: 120 / 2,
          indexHintHeight: 100 / 2,
          indexHintDecoration: BoxDecoration(
            image: DecorationImage(
              image: AssetImage(Utils.getImgPath('ic_index_bar_bubble_gray')),
              fit: BoxFit.contain,
            ),
          ),
          indexHintAlignment: Alignment.centerRight,
          indexHintChildAlignment: const Alignment(-0.25, 0.0),
          indexHintOffset: const Offset(-20, 0),
        ),
      ),
    );
  }
}
